<?php
namespace tools;
include_once dirname(__FILE__).'/getui/GTClient.php';

use think\facade\Log;
class GeTui
{
    public function pushToSingleByCids($title,$body,$cid,$ClickType='none',$ClickUrl=''){
        //创建API，APPID等配置参考 环境要求 进行获取
        $api = new \GTClient("https://restapi.getui.com","JjEiighA4qA8MhhXgCVqP8", "padRhsMBNm8qufGysJSiG4","Bb5mbrZi286Z4tFupHC0J2");
        //设置推送参数
        $push = new \GTPushRequest();
        $push->setRequestId($this->micro_time());
        $message = new \GTPushMessage();
        $notify = new \GTNotification();
        $notify->setTitle($title);
        $notify->setBody($body);
        //点击通知后续动作，目前支持以下后续动作:
        //1、intent：打开应用内特定页面url：打开网页地址。2、payload：自定义消息内容启动应用。3、payload_custom：自定义消息内容不启动应用。4、startapp：打开应用首页。5、none：纯通知，无后续动作
        $notify->setClickType($ClickType);
        if($ClickUrl){
            $notify->setIntent($ClickUrl);
        }
        $message->setNotification($notify);
        $push->setPushMessage($message);
        $push->setCid($cid);
        //处理返回结果
        $result = $api->pushApi()->pushToSingleByCid($push);
    }
    public function micro_time()
    {
        list($usec, $sec) = explode(" ", microtime());
        $time = ($sec . substr($usec, 2, 3));
        return $time;
    }

}

